﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class ST05DeviceManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST05DeviceManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
            //开启定时器任务
            //DispatcherTimer dispatcherTimer = new DispatcherTimer();
            //dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            //dispatcherTimer.Tick += OnTick;
            //dispatcherTimer.Start();


        }

        //private void OnTick(object? sender, EventArgs e)
        //{
        //    ST5PressureCurrentValue = OtherDevicePLCToPC_Global.testData2s[0].CurrentValue;
        //    ST5PressureResult = OtherDevicePLCToPC_Global.testData2s[0].Result[0];
        //    ST5HeightCurrentValue = OtherDevicePLCToPC_Global.testDatas[1].CurrentValue;
        //    ST5HeightResultValue = OtherDevicePLCToPC_Global.testDatas[1].ResultValue;
        //    ST5HeightResult = OtherDevicePLCToPC_Global.testDatas[1].Result[0];
        //}

        private void InitParam()
        {
            ST5HoldingTime= TestPressure_Global.testPressures[0].HoldingTime;
            ST5HoldingPressure = SetPressure_Global.pressures[0];
            ST5HeightSettingTime = TestHigh_Global.testValues[1].SettingTime;
        }



        #region 事件
        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST05");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST05View, param);
        }




        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "ST5HoldingTime":
                    TestPressure_Global.testPressures[0].HoldingTime = ST5HoldingTime;
                    break;

                case "ST5HoldingPressure":
                    SetPressure_Global.pressures[0] = ST5HoldingPressure;
                    break;
                case "ST5HeightSettingTime":
                    TestHigh_Global.testValues[1].SettingTime = ST5HeightSettingTime;
                    break;
                default:
                    break;
            }
        }

        #endregion

        #region 属性
 
        private short _ST5HoldingTime;
        public short ST5HoldingTime
        {
            get { return _ST5HoldingTime; }
            set { SetProperty(ref _ST5HoldingTime, value); }
        }

        private float _ST5HoldingPressure;
        public float ST5HoldingPressure
        {
            get { return _ST5HoldingPressure; }
            set { SetProperty(ref _ST5HoldingPressure, value); }
        }

        private short _ST5HeightSettingTime;
        public short ST5HeightSettingTime
        {
            get { return _ST5HeightSettingTime; }
            set { SetProperty(ref _ST5HeightSettingTime, value); }
        }
        #endregion
    }
}
